package GUILayer.TableModel;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import DataLayer.Model.DelOrdre;

@SuppressWarnings("serial")
public class ButikTableModel extends AbstractTableModel
{
	private ArrayList<DelOrdre> li = new ArrayList<DelOrdre>();
	private String[] columnNames = { "ID", "Type", "Model", "Direct Only",
			"Antal", "Pris" };

	public ButikTableModel()
	{
	}

	public void PopulateList(ArrayList<DelOrdre> list)
	{
		if (list != null)
		{
			this.li = list;
		}
	}

	@Override
	public String getColumnName(int columnIndex)
	{
		return columnNames[columnIndex];
	}

	@Override
	public int getRowCount()
	{
		return li.size();
	}

	@Override
	public int getColumnCount()
	{
		return 6;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex)
	{
		if (li.size() > rowIndex)
		{
			DelOrdre d = li.get(rowIndex);
			switch (columnIndex)
			{
			case 0:
				return d.getDelordreId();
			case 1:
				return d.getProdukt().getType();
			case 2:
				return d.getProdukt().getModel();
			case 3:
				return (d.getProdukt().isDirectOnly()) ? "Ja" : "Nej";
			case 4:
				return d.getAntal();
			case 5:
				return d.getDelTotal();
			}
		}
		return null;
	}

	@Override
	public Class<?> getColumnClass(int columnIndex)
	{
		switch (columnIndex)
		{
		case 0:
			return int.class;
		case 1:
			return String.class;
		case 2:
			return String.class;
		case 3:
			return String.class;
		case 4:
			return String.class;
		case 5:
			return (li.isEmpty()) ? double.class : getValueAt(0, columnIndex).getClass();
		}
		return null;
	}
}